﻿using MES.Desktop.Common;
using MES.Desktop.IService;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MES.Desktop.SystemModule.Models
{
    public class DepartModel : DataModelBase
    {
        public DepartModel() { }

        IDepartService _departService;
        public DepartModel(IDepartService departService)
        {
            _departService = departService;
        }

        private bool _isSelected;

        public bool IsSelected
        {
            get { return _isSelected; }
            set { SetProperty<bool>(ref _isSelected, value); }
        }

        public int Index { get; set; }

        public int DepartId { get; set; }

        private string _departName;

        public string DepartName
        {
            get { return _departName; }
            set
            {
                SetProperty<string>(ref _departName, value);

                this.ClearErrors();
                if (string.IsNullOrEmpty(_departName))
                {
                    this.RaiseErrors("部门名不能为空");
                }
                if (_departService != null && _departService.CheckName(value, DepartId))
                {
                    this.RaiseErrors("部门名不能重复");
                }
            }
        }

    }
}
